$(document).ready(function() {

	/* 轮播图 */
	var swiper_slide = $(".home-hero .swiper-container .swiper-wrapper .swiper-slide");

	let i = 0;
	let index = $(swiper_slide).length;
	var swiper_wrapper = $(swiper_slide).parent();
	let width = $(swiper_wrapper).css("width");
	width = width.substring(0, width.length - 2);
	var swiper_pagination_bullets = $(swiper_wrapper).siblings(".swiper-pagination").children();
	var swiper_slide_time = setInterval(function() {
		swipter_time(i);
		iAdd();
	}, 5000);

	var swiper_button_next = $(swiper_wrapper).siblings(".swiper-button-next");
	$(swiper_button_next).click(function() {
		iAdd();
		swipter_time(i);
	});

	var swiper_button_prev = $(swiper_wrapper).siblings(".swiper-button-prev");
	$(swiper_button_prev).click(function() {
		iSubtract();
		swipter_time(i);
	});
	$(swiper_pagination_bullets).click(function() {
		swipter_time($(this).index());
	});

	function swipter_time(i) {
		$(swiper_slide).css({
			"opacity": "0",
			"transform": "translate3d(0px, 0px, 0px)"
		});
		$(swiper_slide).eq(i).css({
			"opacity": "1",
			"transform": "translate3d(-" + (width * i) + "px, 0px, 0px)"
		});
		$(swiper_pagination_bullets).removeClass("swiper-pagination-bullet-active");
		$(swiper_pagination_bullets).eq(i).addClass("swiper-pagination-bullet-active");
	}

	function iAdd() {
		i++;
		if (i == index)
			i = 0;
	}

	function iSubtract() {
		i--;
		if (i < 0)
			i = index - 1;
	}

	/* div 显示/隐藏 */
	// header downloadApp
	var topbar_download = $("header .topbar-download");
	topbar_download.mouseenter(function() {
		$(this).addClass("active");
	});
	topbar_download.mouseleave(function() {
		$(this).removeClass("active");
	});

	//header cart
	var topbar_cart = $("header .topbar-cart");
	topbar_cart.mouseenter(function() {
		$(this).addClass("topbar-cart-active");
		$(this).find(".cart-menu ").attr("style", "height: 100px;");
	});
	topbar_cart.mouseleave(function() {
		$(this).removeClass("topbar-cart-active");
		$(this).find(".cart-menu ").attr("style", "height: 0;");
	});

	// header nav-item
	var nav_item = $(".site-header .nav-item");
	nav_item.mouseenter(function() {
		var item_children = $(this).find(".item-children").html();
		var header_nav_menu = $(".site-header .header-nav-menu");
		if (item_children == undefined) {
			$(header_nav_menu).html(null);
			nav_item_index = 0;
		} else {
			$(header_nav_menu).css({
				"display": "block"
			});
			if ($(header_nav_menu).css("display") == "block") {

			}
			$(header_nav_menu).removeClass("slide-up");
			$(header_nav_menu).addClass("header-nav-menu-active slide-down");
			$(header_nav_menu).html(item_children);
			nav_item_index = 1;
		}
		if (nav_item_index == 0) {
			$(header_nav_menu).removeClass("slide-down");
			$(header_nav_menu).addClass("slide-up");
		}
	});
	var nav_item_index = 0;
	nav_item.mouseleave(function() {
		var header_nav_menu = $(".site-header .header-nav-menu");
		if (nav_item_index == 0) {
			$(header_nav_menu).removeClass("slide-down");
			$(header_nav_menu).addClass("slide-up");
		}
		nav_item_index = 0;
	});
	var header_nav_menu = $(".site-header .header-nav-menu");
	header_nav_menu.mouseleave(function() {
		if (nav_item_index == 0) {
			$(header_nav_menu).removeClass("slide-down");
			$(header_nav_menu).addClass("slide-up");
		}
		nav_item_index = 0;
	});

	//header category-item
	var category_item = $("header .category-item");
	category_item.mouseenter(function() {
		$(this).addClass("category-item-active");
		$(this).find(".children.clearfix.children-col-4").attr("style", "display: block;");
	});
	category_item.mouseleave(function() {
		$(this).removeClass("category-item-active");
		$(this).find(".children.clearfix.children-col-4").attr("style", "display: none;");
	});

	var tab_list = $(".xm-plain-box .box-hd .more .tab-list li");
	tab_list.mouseenter(function() {
		var zli = $(this).siblings("li");
		zli.removeClass("tab-active");
		$(this).addClass("tab-active");
		var index = $(this).index();
		var tab_list_parent = $(this).parent().parent().parent().parent().find(".span16").children(
			"div").children("ul");
		$(tab_list_parent).addClass("hide");
		$(tab_list_parent).eq(index).removeClass("hide");

	});

	// J_followWx
	var J_followWx = $("#J_followWx");
	J_followWx.mouseenter(function() {
		$(this).siblings("img").css({
			"display": "block"
		});
	});
	J_followWx.mouseleave(function() {
		$(this).siblings("img").css({
			"display": "none"
		});
	});

});
